<template>
  <a-checkbox v-model="val" :disabled="disabled"><slot></slot></a-checkbox>
</template>

<script>
export default {
  model: {
    prop: 'modelVal',
    event: 'change'
  },
  props: {
    modelVal: {
      type: [Number, Boolean],
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      val: false
    }
  },
  mounted () {
    this.init()
  },
  watch: {
    modelVal (v) {
      this.init()
    },
    val (v) {
      this.$emit('change', v)
    }
  },
  methods: {
    init () {
      if (typeof this.modelVal === 'number') {
        this.val = this.modelVal === 1
      } else {
        this.val = this.modelVal
      }
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
